Skip to content

Use simple type and -nofork in nbd@ systemd service - #200

Open
candrews wants to merge 1 commit into
NetworkBlockDevice:masterfrom
candrews:patch-2
Open

candrews wants to merge 1 commit into
NetworkBlockDevice:masterfrom
candrews:patch-2

Conversation

@candrews

@candrews candrews commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

As of eac55e0, when persist mode is active, nbd-client doesn't exit.

By changing the systemd service to simple type and passing nofork to nbd-client , behavior is consistent between persist and non-persist, allowing the service to work as expected for both configurations.

@candrews

candrews commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@yeo should nbd@.service.sh.in or nbd@.service.tmpl be updated?

And can we delete the one that's not used?

@yoe

yoe commented Sep 14, 2026

Copy link
Copy Markdown
Member

As of e906c55 the duplicate file is now removed.

This was there because at once upon a time the sh.in file was generated from the .tmpl file, but that is no longer the case and having both there is turning out to be a bad idea :)

As of eac55e0, when persist mode is active, `nbd-client` doesn't exit.

By changing the systemd service to simple type and passing `nofork` to `nbd-client` , behavior is consistent between persist and non-persist, allowing the service to work as expected for both configurations.
@yoe

yoe commented Sep 14, 2026

Copy link
Copy Markdown
Member

So I'm not sure I 100% understand the proposed change.

Can you explain how the proposed change will work in both persisting and not-persisting mode, and why I should merge it? :)

@candrews

Copy link
Copy Markdown
Contributor Author

Can you explain how the proposed change will work in both persisting and not-persisting mode

Thinking about this more, I don't think this is the right solution to the problem I'm attempting to solve.

The problem is that when using persist mode, the systemd service hangs when starting, stuck in the "activating" state until it times out:

# systemctl status nbd@nbd0
● nbd@nbd0.service - NBD client connection for nbd0
     Loaded: loaded (/usr/lib/systemd/system/nbd@.service; enabled; preset: disabled)
    Drop-In: /etc/systemd/system/nbd@nbd0.service.d
             └─override.conf
     Active: activating (start) since Mon 2026-09-14 13:55:52 EDT; 2s ago
        Job: 3078978
 Invocation: 36a93b057def442d9caf99e9b60f2bfb
       Docs: man:nbd-client
   Main PID: 669130 (nbd-client)
      Tasks: 1 (limit: 19080)
     Memory: 1.3M (peak: 2.2M)
        CPU: 3ms
     CGroup: /system.slice/system-nbd.slice/nbd@nbd0.service
             └─669130 /usr/sbin/nbd-client nbd0

Sep 14 13:55:52 irrational systemd[1]: Starting NBD client connection for nbd0...
Sep 14 13:55:53 irrational nbd-client[669130]: Negotiation: ..size = 1907695MB
Sep 14 13:55:53 irrational nbd-client[669130]: Connected /dev/nbd0
Sep 14 13:55:53 irrational nbd-client[669130]: Persist mode active, monitoring device 0

I think the root cause is the persist mode changes in 5b2d384.

Perhaps the solution is to fork, even in persist mode.

@candrews

Copy link
Copy Markdown
Contributor Author

Also, -nofork doesn't seem to work at all. When persist mode is not set, nbd-client -nofork nbd0 immediately exits when it should not exit

# nbd-client -nofork nbd0
Negotiation: ..size = 1907695MB
Error: Failed to setup device, check dmesg

Exiting.

@yoe

yoe commented Sep 15, 2026

Copy link
Copy Markdown
Member

Can you explain how the proposed change will work in both persisting and not-persisting mode

Thinking about this more, I don't think this is the right solution to the problem I'm attempting to solve.

Right, that's what I was afraid of, but I assumed I must have been wrong :)

[...]

Perhaps the solution is to fork, even in persist mode.

We could do that, but then we should probably have a "force fork" option, so that we are guaranteed to be forking.

Also, -nofork doesn't seem to work at all. When persist mode is not set, nbd-client -nofork nbd0 immediately exits when it should not exit

# nbd-client -nofork nbd0
Negotiation: ..size = 1907695MB
Error: Failed to setup device, check dmesg

Exiting.

I created #201 for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants